import React, { useState, useEffect } from 'react'
import { View, Image, Text } from '@tarojs/components'
import { AtTabs, AtIcon } from 'taro-ui'
import ToLogin from '../../compontents/toLogin'
import Taro, { useDidShow, useShareAppMessage ,useShareTimeline} from '@tarojs/taro'
import useModel from 'flooks';
import store from '../../stores/index'

import api from '../../http/api'
const { nsBusinessList } = api
import TagTab from '../../compontents/tagTab'
import { AtTag } from 'taro-ui'
import "taro-ui/dist/style/components/tag.scss";
import './index.less'

export default (props: any) => {
  const info: any = Taro.getStorageSync('info')
  const  uSchoolId  = info?JSON.parse(info).userInfo.uSchoolId:0
  // 商铺列表
  const [busList, setBusList] = useState([])


  useEffect(() => {
    getList()
  }, [])
  useShareAppMessage(res => {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '新生专区',
      path: '/pages/nsBusiness/index'
    }
  })
  useShareTimeline(()=>{
    return {
      title: '新生专区',
      path: '/pages/nsBusiness/index'
    }
  })
  // 页面跳转
  const toPage = (item: any) => {
    const {id,nsTypeId,price} = item
    Taro.navigateTo({
      url:nsTypeId===3?`/pages/nsTel/index?nsBusinessId=${id}&nsTypeId=${nsTypeId}`:`/pages/nsBusinessDetail/index?nsBusinessId=${id}&nsTypeId=${nsTypeId}&telType=0&price=${price}&infoList=no`
    })
  }
  // 获取商家列表
  const getList = () => {
    nsBusinessList({
      uSchoolId,
    }).then((res: any) => {
      const { data } = res
      setBusList(data)
    })
  }
  return (
    <View className='uBusiness'>
      <ToLogin url='/pages/nsBusiness/index'></ToLogin>
      <View className='shopContUl'>
        {
          busList.map((item: any, i: any) => (
            <View className='shopContLi' onClick={() => { toPage(item) }}>
              <Image className='ico' src={item.url.split(',')[0]} ></Image>
              <View className="subTitle">{item.title}</View>
              <View className="price">
                <Text className="priceNow">¥{item.price}</Text>
                {/* <Text className="priceOld">总数 {item.numTotal}</Text>
                <Text className="priceOld">已售 {item.num}</Text> */}
              </View>
            </View>
          ))
        }
      </View>
    </View>
  );
};
